﻿using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

class MainClass
{
	static void Main(string[] args)
	{
		try
		{
			Run(args[0]);
		}
		catch (Exception e)
		{
			Console.SetOut(Console.Error);
			Console.Write(e.ToString());
		}
	}

	static void Run(string filename)
	{
		string text = null;

		XmlDocument doc = new XmlDocument();

		if (filename == "-")
		{
			text = Console.In.ReadToEnd();
		}
		else
		{
			text = File.ReadAllText(filename);
		}

		int pos = text.IndexOf('<');
		if (pos > 0)
		{
			text = text.Substring(pos);
		}

		doc.LoadXml(text);

		if (filename == "-")
		{
			doc.Save(Console.Out);
		}
		else
		{
			XmlTextWriter writer = new XmlTextWriter(filename + ".new", null);
			writer.Formatting = Formatting.Indented;
			doc.Save(writer);
			writer.Close();
		}
	}
}
